﻿using System.Windows;
using System.Windows.Controls;
using Dsl.Ped.Framework.Common;

namespace Dsl.Ped.Framework.Projections.CollectionProjections.Vertical
{
    /// <summary>
    /// Selector of the templates used in the vertical projection
    /// </summary>
    public class ObjectDataTemplateSelector : DataTemplateSelector
    {
        /// <summary>
        /// Select the proper template based on the type of <see cref="item"/>.
        /// Different templates are used for the IProjective, IProjection, objects 
        /// </summary>
        /// <param name="item">Item which template we are looking for</param>
        /// <param name="container">Container in which the item is placed</param>
        /// <returns><see cref="DataTemplate"/> suitable for the item</returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var frameworkElement = container as FrameworkElement;
            if (frameworkElement == null)
            {
                return null;
            }

            if (item is IProjective)
            {
                return frameworkElement.FindResource("projectiveObjectTemplate") as DataTemplate;
            } 
            else if (item is IProjection)
            {
                return frameworkElement.FindResource("projectionTemplate") as DataTemplate;
            } 
            else
            {
                return frameworkElement.FindResource("objectTemplate") as DataTemplate;
            }
        }
    }
}
